﻿<?php


class ModuleApp extends BaseApp
{

    var $type = NULL;
    var $table_id = 0;
	var $view_data = array();
	var $view_scup_dir = '';

	function __construct() 
	{
      $this->ModuleApp();
	}
		
	function ModuleApp() 
	{
	   $this->view_scup_dir = ROOT_PATH.'/scup/view/'.VIEW_TYPE;   
	   parent::__construct();
	}	
	

    function index()
    {

		$TB_module = &$this->_model('module'); 	 
		
		$infos = $TB_module->show();
        $this->assign('infos', $infos);		
    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('module_list.view.php');
    }
	
    function modhtml()
    {
        if(!isset($_GET['cat']))
		{
		$_GET['cat']='';
		}
        if(!isset($_GET['appid']))
		{
		$_GET['appid'] ='';
		}		
		
        $cat = intval($_GET['cat']);
	    $appid = intval($_GET['appid']);
		$TB_module = &$this->_model('module');		
		$data = $TB_module->oneshow($appid);
		$appname = $data['appname'];
        if(!$appname)
		{
		$notice = &get_message(array('msg'=>"不存在此模块，静态失败",'url'=>'','title'=>'Notice'));
		 $notice ->display();
		}
		$view = &get_view();
		$view->modhtml($cat,SITE_URL ."/?app={$appname}&act=index&cat={$cat}",$appname);
		$this->index(); 
    }
		

	
    function edit()
    {	

		$id = $_GET['id'];
		$TB_module = &$this->_model('module'); 	 	 
		
		$data = $TB_module->oneshow($id);
	
        $data['selectlist'] = unserialize($data['selectlist']);

		if(!is_array($data['selectlist']))
		{
		$data['selectlist'] = array();
		}
		$select_str = '';
 		foreach($data['selectlist'] as $key =>$value)
		{    
		     $str='';
			 		 
		    foreach($value as $key1=>$value1)
			{  
			   if(is_array($value1))
			   {
			      foreach($value1 as $key2 => $value2)
				  {
			       $str.=$value2['name'].':'.$value2['where'].'|';				  
				  }
				   
			   }
			   else
			   {
			   $str.=$key1.':'.$value1.'|';			   
			   }

			}
			$select_str.=$str.'#';
		}		
		
/* 		foreach($data['selectlist'] as $key =>$value)
		{    
		     $str='';
			 		 
		    foreach($value as $key1=>$value1)
			{  
			   if(is_array($value1))
			   {
			      foreach($value1 as $key2 => $value2)
				  {
			       $str.=$key1.'['.$key2.'][name].'.$value2['name'].':'.$key1.'['.$key2.'][where].'.$value2['where'].':';				  
				  }
				   
			   }
			   else
			   {
			   $str.=$key1.'.'.$value1.':';			   
			   }

			}
			$select_str.=$str.'|';
		} */
        $select_str = str_replace(array(';suang;',";dang;"),array('&quot;','&#39;'),$select_str);		
		$data['selectlist'] = $select_str;
	    $this->assign('data', $data);		
			

        $this->assign('viewdata', $this->get_view_data());
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('module_edit.view.php');
    }

    function editpost()
    {

	     $data = $_POST['data'];
	     if(!preg_match("/^([a-z]{2,})$/i",$data['appname']))
		 {	
		 $notice = &get_message(array('msg'=>'模块APP名只能是字母！','url'=>'','title'=>'Notice'));
		 $notice ->display();		 
	     }			 

 	     if(!empty($data['selectlist']))
		 {


		    $data['selectlist'] = str_replace(array('&quot;','&#39;','\\'),array(';suang;',";dang;",''),$data['selectlist']);

		  $selectlist = array();
		  $tempselect = $data['selectlist'];
		  $temparray = del_empty_var(explode("#",$tempselect)); 
	      foreach($temparray as $key=>$value)
		  { 
			$temp = array();
		    $temp = del_empty_var(explode('|',$value)); 
			$num = 1 ;
            foreach($temp as $key1 => $value1)
			{ 
			  $temp1 = array();
		      $temp1 = del_empty_var(explode(":",$value1));
              $temp1[0] = trim($temp1[0]);
			  $temp1[1] = trim($temp1[1]);
		      if( $temp1[0]=='filedname' || $temp1[0]=='to' )
		      {
		        $selectlist[$key][$temp1[0]] = $temp1[1];		   
		      } else {
		        $selectlist[$key]['data'][$num]['name'] = $temp1[0];
		        $selectlist[$key]['data'][$num]['where'] = $temp1[1];
                $num ++ ; 				
			  }			  			  		  
		  
			} 				  				
		  }			 
         unset($data['selectlist']);

		 $data['selectlist']=serialize($selectlist);		 
		 } 		 
		 
		 
/* 	     if(!empty($data['selectlist']))
		 {
		  $selectlist = array();
		  $tempselect = $data['selectlist'];
		  $temparray = del_empty_var(explode("|",$tempselect)); 
	      foreach($temparray as $key=>$value)
		  { 
			$temp = array();
		    $temp = del_empty_var(explode(":",$value)); 
            foreach($temp as $key1 => $value1)
			{ 
			  $temp1 = array();
		      $temp1 = del_empty_var(explode(".",$value1));

		      if(strstr($temp1[0],'data['))
		      {
			      if(strstr($temp1[0],'][name]'))
				  {
				    $num = str_replace(array('data[','][name]'),array('',''),$temp1[0]);
					
		            $selectlist[$key]['data'][$num]['name'] = $temp1[1];			  
				  }
				  else if(strstr($temp1[0],'][where]'))
				  {
				   $num = str_replace(array('data[','][where]'),array('',''),$temp1[0]);

		           $selectlist[$key]['data'][$num]['where'] = $temp1[1];				  
				  }
			   
		      }
			  else
			  {
		      $selectlist[$key][$temp1[0]] = $temp1[1];				  
			  }			  			  		  
		  
			} 				  				
		  }			 
         unset($data['selectlist']);
		 
		 $data['selectlist']=serialize($selectlist);		 
		 } */

		 
		 if(empty($data['viewname']))
		 {
		 $data['viewname'] = 'content.view.html';
		 }

		 $id = intval($data['id']);	
		 $TB_module = &$this->_model('module'); 
		 $TB_module->editaction($id,$data);	 
         $this->write_cache();	
		 $this->write_power_cache();
	     $this->produced_html($id);		  
		 $this->index();
		 

    }

	
	
	
	
	
	
	
	
	
	
	
	
    function add()
    {	

        $this->assign('viewdata', $this->get_view_data());		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('module_add.view.php');
    }


    function addpost()
    {
	     $data = $_POST['data'];
	     if(!preg_match("/^([a-z]{2,})$/i",$data['appname']))
		 {	
		 $notice = &get_message(array('msg'=>'模块APP名只能是字母！','url'=>'','title'=>'Notice'));
		 $notice ->display();		 
	     }		 
		 
		 $TB_module = &$this->_model('module'); 
		 $check_icon = $TB_module->check_name($data['name'],$data['appname']);
	     if($check_icon)
		 {
		 $notice = &get_message(array('msg'=>'当前模块名称或APP名已经存在了,请更换！','url'=>'','title'=>'Notice'));
		 $notice ->display();		
	     }
		 		 	 
         $maxid = $TB_module->get_module_max_id();
		 unset($data['id']);
         $data['id'] = $maxid+1;
		 if(!isset($data['config']))
		 {
		 $data['config'] ='';
		 }
		 $data['config'] = serialize($data['config']);
         if(empty($data['viewname']))
		 {
		 $data['viewname'] = 'content.view.html';
		 }

		 $TB_module->post($data);
         
		 $db = & get_db();
		 if($db->table_exists(DB_PREFIX."content_".$data['id'].""))
		 {
		 $notice = &get_message(array('msg'=>'此数据库表已经存在了！','url'=>'','title'=>'Notice'));
		 $notice ->display();			 
		 }



         $SQL ='';	
	     if(DB_CHARSET && $db->version() > '4.1' )
		 {	
		  $SQL=" DEFAULT CHARSET=".DB_CHARSET." ";	
	     }
	
	     $sql="CREATE TABLE `".DB_PREFIX."content_".$data['id']."` (
        `id` mediumint(7) unsigned NOT NULL auto_increment COMMENT '主表id',
        `cat_id` mediumint(7) NOT NULL default '0' COMMENT '分类id',
        `user_id` int(10) NOT NULL default '0' COMMENT '发布者id',
        `user_name` varchar(50) NOT NULL default '0' COMMENT '发布者用户名',
        `keywords` varchar(255) NOT NULL default ' ' COMMENT '关键字，标签',
        `description` varchar(255) NOT NULL default ' ' COMMENT '简要描述用于SEO优化',
        `visit_num` mediumint(7) unsigned NOT NULL default '0' COMMENT '访问次数',
        `hit_num` mediumint(7) unsigned NOT NULL default '0' COMMENT '顶的次数',
        `hui_num` mediumint(7) unsigned NOT NULL default '0' COMMENT '回复的次数',		
        `add_time` int(10) NOT NULL default '0' COMMENT '添加时间',
        `lastview` int(10) NOT NULL default '0' COMMENT '最后访问时间',
        `is_show` tinyint(1) NOT NULL default '1' COMMENT '1显示，0隐藏',
        `is_top` tinyint(1) NOT NULL default '1' COMMENT '1置顶，0不自顶',
        `is_recommend` tinyint(1) NOT NULL default '1' COMMENT '1推荐，0非推荐',
        `is_index` tinyint(1) NOT NULL default '1' COMMENT '1在主页头条，0非',
        `config` text NULL default NULL COMMENT '属性',
         PRIMARY KEY  (`id`)
     	) ENGINE=MyISAM ".$SQL." AUTO_INCREMENT=1 ;";	
		
		
    	$db->query($sql);
					 
         $this->write_cache();
		 $this->write_power_cache();
         $this->write_module_default_html($data['id']);		 
		 $this->write_module_default_scup_html($data['id'],$data['viewname']);
		 $this->index();

    }

    function del()
    {

	     $id = $_GET['id'];
		 $db = & get_db();

	     $rs=$db->get_one("SELECT count(*) AS num FROM ".DB_PREFIX."content_{$id}  WHERE user_id>0 and user_name!='0' ");	
	     if($rs['num'])
		 {	
		 $notice = &get_message(array('msg'=>'本模块已有内容了,请先删除内容','url'=>'','title'=>'Notice'));
		 $notice ->display();			
	     }		 

		 $TB_module = &$this->_model('module'); 
		 $data = $TB_module->oneshow($id);		

		 $rs=$db->get_one("SELECT count(*) AS num FROM ".DB_PREFIX."category WHERE type='".$data['appname']."' ");	
	     if($rs['num'])
		 {	
		 $notice = &get_message(array('msg'=>'本模块还存在分类,请先删除分类','url'=>'','title'=>'Notice'));
		 $notice ->display();			
	     }		 
		 
		 $TB_module->del($id);		 

		 if(!$db->table_exists(DB_PREFIX."content_{$id}"))
		 {
		 $notice = &get_message(array('msg'=>'此数据库表已经不存在了！','url'=>'','title'=>'Notice'));
		 $notice ->display();			 
		 }
	     $db->query(" DROP TABLE IF EXISTS `".DB_PREFIX."content_{$id}`");		 
		 
         $this->write_cache();
		 $this->write_power_cache();

         $dir_array = array($this->view_scup_dir."/content_{$id}.view.html",
		 $GLOBALS['SCup']->SCup_view_root."/content_{$id}_list.view.html",
		 $GLOBALS['SCup']->SCup_view_root."/content_{$id}_add.view.html",
		 $GLOBALS['SCup']->SCup_view_root."/content_{$id}_edit.view.html",
		 );
		 foreach ($dir_array as $key => $value)
		 {
		    if(!is_dir($value)&&file_exists($value))
		    {
		     del_file($value);	
		    }		 
		 }		 
				 	
		 $this->index();

    }
	
    function lcsort()
    {
		 $data = array();
		 
	     $id = $_GET['id'];
		 $data['sort'] = $_GET['v'];
		 		 
		 $TB_module = &$this->_model('module');  	 		
		 $TB_module->editsort($id,$data); 
         $this->write_cache();	 
		 $this->index();			  

    }



   function filedlist($id=0)
    {
	    if($id==0)
		{
        $id = intval($_GET['id']);
		}
		
		$TB_module = &$this->_model('module'); 	 
		
		$data = $TB_module->oneshow($id);
		
		$field_config = unserialize($data['config']);
		
        $this->assign('fieldconfig', $field_config);		
 
        $this->assign('id', $id);	   
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('module_filedlist.view.php');
    }
	
	
    function filedadd()
    {	
        $id = intval($_GET['id']);	
        $sxarray1 = get_all_dirname(ROOT_PATH . '/data/sx');
		$sxarray = array();
	    foreach($sxarray1  as $key => $value)
		{
		   if(strpos($value,'.php') && strstr($value,'sx_'))
		   {
		      $strid = str_replace(array('.php','sx_'),array('',''),$value);
			  $tempname = $this->get_sx_cache($strid); 
		      $sxarray[$tempname] = $value;
		   }
		}		

        $this->assign('sxarray', $sxarray);
		
        $this->assign('filter_data', $GLOBALS['SCup']->SCup_filter_app->_table_list);
					
		$mdivdata = $this->get_module_data();

        $this->assign('mdivdata', $mdivdata);
	
        $this->assign('id', $id);				
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('module_filedadd.view.php');
    }

    function filededit()
    {	
        $id = intval($_GET['id']);	
        $tbid = intval($_GET['tbid']);

        $sxarray1 = get_all_dirname(ROOT_PATH . '/data/sx');
		$sxarray = array();
	    foreach($sxarray1  as $key => $value)
		{
		   if(strpos($value,'.php') && strstr($value,'sx_'))
		   {
		      $strid = str_replace(array('.php','sx_'),array('',''),$value);
			  $tempname = $this->get_sx_cache($strid); 
		      $sxarray[$tempname] = $value;
		   }
		}		

        $this->assign('sxarray', $sxarray);
		 $TB_module = &$this->_model('module'); 	 
         $field_one_info = $TB_module->oneshow($id);
	     $field_config_data = unserialize($field_one_info['config']);
	     $data = $field_config_data[$tbid];
		 if(empty($data)||!is_array($data))
		 {
           $data = array();
		 }

        $this->assign('data', $data);			
        $this->assign('filter_data', $GLOBALS['SCup']->SCup_filter_app->_table_list);			
		$mdivdata = $this->get_module_data();
        $this->assign('mdivdata', $mdivdata);
	
        $this->assign('id', $id);
        $this->assign('tbid', $tbid);						
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('module_filededit.view.php');
    }



    function filedpostadd()
    {

         $id = intval($_POST['id']);

	     $data = $_POST['data'];
		 

		 $tempdata = $temptype = '';
		 $filterstr ='';
		 if(isset($data['filter']) && !empty($data['filter']))
		 {
		 $filterstr ='_s_'.$data['filter'];
		 }		 
		 $temptype = $data['form']['type'];
		 $tempdata = $data['form'][$data['form']['type']];
		 unset($data['form']);
		 $data['form']['type'] = $temptype;
		 $data['form']['icon'] = $data['filed']['cname'];			 
		 $data['form'][$data['form']['type']] = $tempdata;
		 $data['form'][$data['form']['type']]['name'] = 'data['.$data['filed']['name'].$filterstr.']';	
		 $data['form']['sx_data'] = $data['sx_data'];
		 $data['form']['sxdatatype'] = $data['sxdatatype'];	
		 $data['form']['tips'] = $data['form_tips'];
		 $data['form']['filter'] = $data['filter'];		 			 		 
		 unset($data['sx_data'],$data['form_tips'],$data['filter']);

	 
	    if(!preg_match("/^([a-z])([a-z0-9_]{2,})$/i",$data['filed']['name']))
		{	
		 $notice = &get_message(array('msg'=>'数据库字段名不符合规则','url'=>'','title'=>'Notice'));
		 $notice ->display();		 
	    }

		 $db = & get_db();		 
		 if($db->check_fields(DB_PREFIX."content_{$id}",array($data['filed']['name']=>'0')))
		 {
		 $notice = &get_message(array('msg'=>'此数据库字段名已存在,请更换一个！','url'=>'','title'=>'Notice'));
		 $notice ->display();			 
		 }
		 $filedstr = $this->get_field_str($data['filed']['name'],$data['filed']['type'],$data['filed']['length'],$data['filed']['isnull'],$data['filed']['defaultv'],'', $data['tips'],false);

		 $db->query("ALTER TABLE `".DB_PREFIX."content_{$id}` ADD ".$filedstr);	


		 $TB_module = &$this->_model('module'); 	 
         $field_one_info = $TB_module->oneshow($id);
		 
	     $field_config_data = unserialize($field_one_info['config']);
 
		 if(empty($field_config_data)||!is_array($field_config_data))
		 {
           $field_config_data = array();
		 }
		 	 
		 array_push($field_config_data,$data);
		 unset($dataconfig);

		 $dataconfig['config'] = serialize($field_config_data);		 
		 $TB_module->editaction($id,$dataconfig);
         $this->write_cache();
	     $this->produced_html($id);		 		 		 
	     $this->filedlist($id);


    }

   function filedpostedit()
    {

         $id = intval($_POST['id']);
         $tbid = intval($_POST['tbid']);
	     $data = $_POST['data'];
		 $tempdata = $temptype = '';
		 $filterstr ='';
		 if(isset($data['filter']) && !empty($data['filter']))
		 {
		 $filterstr ='_s_'.$data['filter'];
		 }
		 $temptype = $data['form']['type'];
		 $tempdata = $data['form'][$data['form']['type']];
		 unset($data['form']);
		 $data['form']['type'] = $temptype;
		 $data['form']['icon'] = $data['filed']['cname'];			 
		 $data['form'][$data['form']['type']] = $tempdata;
		 $data['form'][$data['form']['type']]['name'] = 'data['.$data['filed']['name'].$filterstr.']';		 
		 $data['form']['sx_data'] = $data['sx_data'];
		 $data['form']['sxdatatype'] = $data['sxdatatype'];	
		 $data['form']['tips'] = $data['form_tips'];	
		 $data['form']['filter'] = $data['filter'];			 	 		 
		 unset($data['sx_data'],$data['form_tips'],$data['filter']);

	    if(!preg_match("/^([a-z])([a-z0-9_]{2,})$/i",$data['filed']['name']))
		{	
		 $notice = &get_message(array('msg'=>'数据库字段名不符合规则','url'=>'','title'=>'Notice'));
		 $notice ->display();		 
	    }

		 $db = & get_db();	
		 	 
/*		 if($db->check_fields(DB_PREFIX."content_{$id}",array($data['filed']['name']=>'0')))
		 {
		 $notice = &get_message(array('msg'=>'此数据库字段名已存在,请更换一个！','url'=>'','title'=>'Notice'));
		 $notice ->display();			 
		 }
*/



		 $TB_module = &$this->_model('module'); 	 
         $field_one_info = $TB_module->oneshow($id);
		 
	     $field_config_data = unserialize($field_one_info['config']);

		 if(empty($field_config_data)||!is_array($field_config_data))
		 {
           $field_config_data = array();
		 }

		 
		 $filedstr = $this->get_field_str($data['filed']['name'],$data['filed']['type'],$data['filed']['length'],$data['filed']['isnull'],$data['filed']['defaultv'],'', $data['tips'],false);		 	
		 $db->query("ALTER TABLE `".DB_PREFIX."content_{$id}` CHANGE `".$field_config_data[$tbid]['filed']['name']."` ".$filedstr);	 
		 		 
		 
         $field_config_data[$tbid] = $data;	
		 unset($dataconfig);		 
		 $dataconfig['config'] = serialize($field_config_data);		 
		 $TB_module->editaction($id,$dataconfig);
         $this->write_cache();	
	     $this->produced_html($id);		 	 		 
	     $this->filedlist($id);


    }

   function fileddel()
    {

         $id = intval($_GET['id']);
         $tbid = intval($_GET['tbid']);
		 $TB_module = &$this->_model('module'); 	 
         $field_one_info = $TB_module->oneshow($id);
		 
	     $field_config_data = unserialize($field_one_info['config']);
 
		 if(empty($field_config_data)||!is_array($field_config_data))
		 {
           $field_config_data = array();
		 }
		 $db = & get_db();		 
		 $db->query("ALTER TABLE `".DB_PREFIX."content_{$id}` DROP `".$field_config_data[$tbid]['filed']['name']."` ");	 
		 
         if(isset($field_config_data[$tbid]))
		 {
		 unset($field_config_data[$tbid]);
		 } 
		 
		 unset($dataconfig);		 
		 $dataconfig['config'] = serialize($field_config_data);		 
		 $TB_module->editaction($id,$dataconfig);
         $this->write_cache();
	     $this->produced_html($id);		 		 		 
	     $this->filedlist($id);

    }

   function viewindex()
    {

	    if(is_file($this->view_scup_dir."/index.view.html"))
		{
		$view_file_index = $this->view_scup_dir.'/index.view.html';		
	    }else
		{
		$view_file_index = $this->view_scup_dir.'/content/index.view.html';
	    }		
	    $view_scup_index=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_index));
        $this->assign('view_file_index', $view_file_index);		
        $this->assign('view_scup_index', $view_scup_index);	
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('module_viewindex.view.php');
    }

	function viewpostindex() 
	{
	    
		$data = $_POST['scupindex'];
		$data= str_replace(array('&quot;','&#39;'),array('"',"'"), $data);	
		
	    $view_scup_index = stripslashes($data);		
     	write_file( $this->view_scup_dir."/index.view.html",$view_scup_index);				
   	    if(!is_writable($this->view_scup_dir."/index.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/index.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
		 $notice = &get_message(array('msg'=>"主页模板修改成功",'url'=>'?app=module&act=viewindex','title'=>'Notice'));
		 $notice ->display();					
		
	}
  	

   function viewlist()
    {

        $id = intval($_GET['id']);

        include(ROOT_PATH . '/lib/div.lib.php');
		$phpscupdiv= new PhpSCup_div($id,'');
        $phpscupdiv_array = $phpscupdiv->get_phpscupdiv($id);
        $this->assign('phpscupdiv_array', $phpscupdiv_array);
	    $this->produced_html($id,'yes');

		 $TB_module = &$this->_model('module'); 
		 $data = $TB_module->oneshow($id);

	    if(is_file($this->view_scup_dir."/content_{$id}.view.html"))
		{
		$view_file_index= $this->view_scup_dir."/content_{$id}.view.html";		
	    }else
		{
		$view_file_index= $this->view_scup_dir.'/content/'.$data['viewname'];
	    }
		
	    $view_scup_index=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_index));

	    if(is_file($this->view_scup_dir."/content_{$id}_list.view.html"))
		{
		$view_file_indexlist= $this->view_scup_dir."/content_{$id}_list.view.html";		
	    }else
		{
		$view_file_indexlist= $this->view_scup_dir.'/content/post/content_list.view.html';
	    }
		
	    $view_scup_indexlist=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_indexlist));

	    if(is_file($this->view_scup_dir."/content_{$id}_add.view.html"))
		{
		$view_file_indexadd= $this->view_scup_dir."/content_{$id}_add.view.html";		
	    }else
		{
		$view_file_indexadd= $this->view_scup_dir.'/content/post/content_add.view.html';
	    }		
	    $view_scup_indexadd=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_indexadd));

	    if(is_file($this->view_scup_dir."/content_{$id}_edit.view.html"))
		{
		$view_file_indexedit= $this->view_scup_dir."/content_{$id}_edit.view.html";		
	    }else
		{
		$view_file_indexedit= $this->view_scup_dir.'/content/post/content_edit.view.html';
	    }		
	    $view_scup_indexedit=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_indexedit));



	    if(is_file($GLOBALS['SCup']->SCup_view_root."/content_{$id}_list.view.html"))
		{
		$view_file_list= $GLOBALS['SCup']->SCup_view_root."/content_{$id}_list.view.html";		
	    }else
		{
		$view_file_list=$GLOBALS['SCup']->SCup_view_root.'/content/content_list.view.html';
	    }
		
	    $view_admin_list=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_list));

	    if(is_file($GLOBALS['SCup']->SCup_view_root."/content_{$id}_add.view.html"))
		{
		$view_file_add= $GLOBALS['SCup']->SCup_view_root."/content_{$id}_add.view.html";		
	    }else
		{
		$view_file_add=$GLOBALS['SCup']->SCup_view_root.'/content/content_add.view.html';
	    }
		
	    $view_admin_add=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_add));		
		

	    if(is_file($GLOBALS['SCup']->SCup_view_root."/content_{$id}_edit.view.html"))
		{
		$view_file_edit= $GLOBALS['SCup']->SCup_view_root."/content_{$id}_edit.view.html";		
	    }else
		{
		$view_file_edit=$GLOBALS['SCup']->SCup_view_root."/content/content_edit.view.html";
	    }
		
	    $view_admin_edit=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_edit));	

        $this->assign('view_file_index', $view_file_index);
        $this->assign('view_file_indexlist', $view_file_indexlist);		
        $this->assign('view_file_indexadd', $view_file_indexadd);		
        $this->assign('view_file_indexedit', $view_file_indexedit);		
		
        $this->assign('view_file_list', $view_file_list);
        $this->assign('view_file_add', $view_file_add);		
        $this->assign('view_file_edit', $view_file_edit);
			
	    $this->assign('view_scup_index', $view_scup_index);
	    $this->assign('view_scup_indexlist', $view_scup_indexlist);
	    $this->assign('view_scup_indexadd', $view_scup_indexadd);		
	    $this->assign('view_scup_indexedit', $view_scup_indexedit);		
		
        $this->assign('view_admin_list', $view_admin_list);
        $this->assign('view_admin_add', $view_admin_add);		
        $this->assign('view_admin_edit', $view_admin_edit);
		 
        $this->assign('id', $id);	   
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('module_viewlist.view.php');
    }

	function viewpost() 
	{
	    
        $id = intval($_POST['id']);
		$data = $_POST['data'];

		$data['scupindex']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['scupindex']);
		$data['scupindexlist']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['scupindexlist']);		
		$data['scupindexadd']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['scupindexadd']);		
		$data['scupindexedit']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['scupindexedit']);
		
				
		$data['admin_list']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['admin_list']);
		$data['admin_add']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['admin_add']);		
		$data['admin_edit']= str_replace(array('&quot;','&#39;'),array('"',"'"), $data['admin_edit']);
				
	    $view_scup_index = stripslashes($data['scupindex']);
	    $view_scup_indexlist = stripslashes($data['scupindexlist']);		
	    $view_scup_indexadd = stripslashes($data['scupindexadd']);		
	    $view_scup_indexedit = stripslashes($data['scupindexedit']);
				
	    $view_admin_list = stripslashes($data['admin_list']);
	    $view_admin_add = stripslashes($data['admin_add']);
	    $view_admin_edit = stripslashes($data['admin_edit']);

     	write_file($this->view_scup_dir."/content_{$id}.view.html",$view_scup_index);
     	write_file($this->view_scup_dir."/content_{$id}_list.view.html",$view_scup_indexlist);		
     	write_file($this->view_scup_dir."/content_{$id}_add.view.html",$view_scup_indexadd);		
     	write_file($this->view_scup_dir."/content_{$id}_edit.view.html",$view_scup_indexedit);
						
     	write_file($GLOBALS['SCup']->SCup_view_root."/content_{$id}_list.view.html",$view_admin_list);
	    write_file($GLOBALS['SCup']->SCup_view_root."/content_{$id}_add.view.html",$view_admin_add);
	    write_file($GLOBALS['SCup']->SCup_view_root."/content_{$id}_edit.view.html",$view_admin_edit);

   	    if(!is_writable($this->view_scup_dir."/content_{$id}.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$id}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }				
   	    if(!is_writable($this->view_scup_dir."/content_{$id}_list.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }	
   	    if(!is_writable($this->view_scup_dir."/content_{$id}_add.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$id}_add.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }	

   	    if(!is_writable($this->view_scup_dir."/content_{$id}_edit.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$id}_edit.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }	

   	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$id}_list.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$id}_add.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$id}_add.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$id}_edit.view.html"))
	    {	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$id}_edit.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();	
	    }
		 $notice = &get_message(array('msg'=>"模板修改成功",'url'=>'?app=module&act=viewlist&id='.$id,'title'=>'Notice'));
		 $notice ->display();					
		
	}
  	



	function get_module_data() 
	{
		return include (ROOT_PATH . '/data/module/module_div.php');
	}
  
	
    function write_cache()
    { 
		$TB_module = &$this->_model('module'); 		
		$infos = $TB_module->show();
		$infos_temp = array();		
		array_var_sort($infos,'sort');		
		foreach($infos as $key => $value)
		{
		   $infos_temp[$value['appname']] = $value;
		}	
			
		$cache_filename = ROOT_PATH . '/data/module/module_list.php';
		
	    write_file($cache_filename, "<?php \nreturn " . var_export($infos_temp , true) . ";\n?>");
		
		if(!is_writable($cache_filename))
		{
		exit('file directory is not writed power');//文件目录权限不可写
	    }
    }	

    function write_power_cache()
    { 
		$TB_module = &$this->_model('module'); 		
		$infos = $TB_module->show();
		$infos_temp = array();		
		array_var_sort($infos,'sort');		
		foreach($infos as $key => $value)
		{
		   $infos_temp[$value['appname']] = $value;
		}	
		
		$default_adminpower = include(ROOT_PATH .'/lib/power/admin.power.php');
		$default_scuppower = include(ROOT_PATH .'/lib/power/scup.power.php');


		foreach($infos_temp as $key=>$value)
		{
           $catdata = $GLOBALS['SCup']->_get_category_data($value["appname"]);
		   if(!isset($catdata[0]['cat_id']))
		   {
               $catdata =   array (
                                     0 => 
                                        array (
                                              'cat_id' => '0',
                                              'cat_name' => '',

                                              ),
                                  );		   
		   }		
		   foreach($catdata as $key1=>$value1)
		   {
		   
	   $default_adminpower[] = array 
       ('name' => $value["name"].'----'.$value1['cat_name'],
	    'app' => $value["appname"],
	    'catid' => $value1['cat_id'],		
		'act' => array 
                     ('index'=>'查看列表',
					  'add:addpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'添加',	
					  'del'=>'删除',
					  'edit:editpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'修改',
					  'cagrylist'=>'分类列表',
					  'cagryadd:cyaddpost'=>'分类添加',	
					  'delcatgy'=>'分类删除',	
					  'editcatgy:cyeditpost'=>'分类修改',	
					  'hui'=>'回复管理',	
					  'batch'=>'批量操作',						  					  																			
                     )
       );
	   $default_scuppower[] = array 
       ('name' => $value["alias"].'----'.$value1['cat_name'],
	    'app' => $value["appname"],
	    'catid' => $value1['cat_id'],			
		'act' => array 
                     ('index'=>'列表',
					  'show'=>'内容显示',	
					  'userlist'=>'用户中心内容列表',						  
					  'add:addpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'添加',	
					  'del'=>'删除',
					  'edit:editpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'修改',
					  'hui'=>'回复管理',						  					  											
                     )
       );		   
		   
		   }



		}


		$cache_filename_admin = ROOT_PATH .'/data/power/data/admin.power.php';
		$cache_filename_scup = ROOT_PATH .'/data/power/data/scup.power.php';	
		
	    write_file($cache_filename_admin, "<?php \nreturn " . var_export($default_adminpower , true) . ";\n?>");
	    write_file($cache_filename_scup, "<?php \nreturn " . var_export($default_scuppower , true) . ";\n?>");
		
		if(!is_writable($cache_filename_admin)||!is_writable($cache_filename_scup))
		{
		exit('file directory is not writed power');//文件目录权限不可写
	    }
    }	

/*    function write_power_cache()
    { 
		$TB_module = &$this->_model('module'); 		
		$infos = $TB_module->show();
		$infos_temp = array();		
		array_var_sort($infos,'sort');		
		foreach($infos as $key => $value)
		{
		   $infos_temp[$value['appname']] = $value;
		}	
		
		$default_adminpower = include(ROOT_PATH .'/lib/power/admin.power.php');
		$default_scuppower = include(ROOT_PATH .'/lib/power/scup.power.php');


		foreach($infos_temp as $key=>$value)
		{
		      $default_adminpower[] = array 
       ('name' => $value['name'],
	    'app' => $value['appname'],
		'act' => array 
                     ('index'=>'查看列表',
					  'add:addpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'添加',	
					  'del'=>'删除',
					  'edit:editpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'修改',
					  'cagrylist'=>'分类列表',
					  'cagryadd:cyaddpost'=>'分类添加',	
					  'delcatgy'=>'分类删除',	
					  'editcatgy:cyeditpost'=>'分类修改',	
					  'hui'=>'回复管理',						  																			
                     )
       );
		      $default_scuppower[] = array 
       ('name' => $value['alias'],
	    'app' => $value['appname'],
		'act' => array 
                     ('index'=>'列表',
					  'show'=>'内容显示',	
					  'add:addpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'添加',	
					  'del'=>'删除',
					  'edit:editpost:kindeditor:kindeditorupfile:upfile:pupfile'=>'修改',
					  'hui'=>'回复管理',						  					  											
                     )
       );


		}


		$cache_filename_admin = ROOT_PATH .'/data/power/data/admin.power.php';
		$cache_filename_scup = ROOT_PATH .'/data/power/data/scup.power.php';	
		
	    write_file($cache_filename_admin, "<?php \nreturn " . var_export($default_adminpower , true) . ";\n?>");
	    write_file($cache_filename_scup, "<?php \nreturn " . var_export($default_scuppower , true) . ";\n?>");
		
		if(!is_writable($cache_filename_admin)||!is_writable($cache_filename_scup))
		{
		exit('file directory is not writed power');//文件目录权限不可写
	    }
    }	*/
		

    function write_module_html()
    { 
		$TB_module = &$this->_model('module'); 		
		$infos = $TB_module->show();
		$infos_temp = array();		
		array_var_sort($infos,'sort');		
		foreach($infos as $key => $value)
		{
		   $infos_temp[$value['appname']] = $value;
		}
					
		$cache_filename = ROOT_PATH . '/data/module/module_list.php';
		
	    write_file($cache_filename, "<?php \nreturn " . var_export($infos_temp , true) . ";\n?>");
		
		if(!is_writable($cache_filename))
		{
		exit('file directory is not writed power');//文件目录权限不可写
	    }
    }


    function write_module_default_scup_html($table_id=0,$viewname='content.view.html')
    {	
		
	    $view_scup_index = stripslashes(read_file($this->view_scup_dir.'/content/'.$viewname));	
     	write_file($this->view_scup_dir."/content_{$table_id}.view.html",$view_scup_index);
		
   	    if(!is_writable($this->view_scup_dir."/content_{$table_id}.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$table_id}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }


    }


    function write_module_default_html($table_id=0)
    {	

	    $view_file_indexlist = stripslashes(read_file($this->view_scup_dir.'/content/post/content_list.view.html'));
	    $view_file_indexadd = stripslashes(read_file($this->view_scup_dir.'/content/post/content_add.view.html'));
	    $view_file_indexedit = stripslashes(read_file($this->view_scup_dir.'/content/post/content_edit.view.html'));

		
	    $view_admin_list = stripslashes(read_file($GLOBALS['SCup']->SCup_view_root.'/content/content_list.view.html'));
	    $view_admin_add = stripslashes(read_file($GLOBALS['SCup']->SCup_view_root.'/content/content_add.view.html'));
	    $view_admin_edit = stripslashes(read_file($GLOBALS['SCup']->SCup_view_root.'/content/content_edit.view.html'));	
		
     	write_file($this->view_scup_dir."/content/post/content_{$table_id}_list.view.html",$view_file_indexlist);
     	write_file($this->view_scup_dir."/content/post/content_{$table_id}_add.view.html",$view_file_indexadd);		
     	write_file($this->view_scup_dir."/content/post/content_{$table_id}_edit.view.html",$view_file_indexedit);				
			
     	write_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html",$view_admin_list);
	    write_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html",$view_admin_add);
	    write_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html",$view_admin_edit);

   	    if(!is_writable($this->view_scup_dir."/content/post/content_{$table_id}_list.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content/post/content_{$table_id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
   	    if(!is_writable($this->view_scup_dir."/content/post/content_{$table_id}_add.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content/post/content_{$table_id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
   	    if(!is_writable($this->view_scup_dir."/content/post/content_{$table_id}_edit.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content/post/content_{$table_id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }



   	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html"))
	    {	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();	
	    }

    }

    function produced_html($table_id=0,$yes='no')
    {	







	    if(is_file($this->view_scup_dir."/content_{$id}_list.view.html"))
		{
		$view_file_indexlist= $this->view_scup_dir."/content_{$id}_list.view.html";		
	    }else
		{
		$view_file_indexlist= $this->view_scup_dir.'/content/post/content_list.view.html';
	    }

	    if(is_file($this->view_scup_dir."/content_{$id}_add.view.html"))
		{
		$view_file_indexadd= $this->view_scup_dir."/content_{$id}_add.view.html";		
	    }else
		{
		$view_file_indexadd= $this->view_scup_dir.'/content/post/content_add.view.html';
	    }		


	    if(is_file($this->view_scup_dir."/content_{$id}_edit.view.html"))
		{
		$view_file_indexedit= $this->view_scup_dir."/content_{$id}_edit.view.html";		
	    }else
		{
		$view_file_indexedit= $this->view_scup_dir.'/content/post/content_edit.view.html';
	    }		




	    if(is_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html"))
		{
		$view_file_list= $GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html";		
	    }else
		{
		$view_file_list=$GLOBALS['SCup']->SCup_view_root.'/content/content_list.view.html';
	    }
	    if(is_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html"))
		{
		$view_file_add= $GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html";		
	    }else
		{
		$view_file_add=$GLOBALS['SCup']->SCup_view_root.'/content/content_add.view.html';
	    }
	    if(is_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html"))
		{
		$view_file_edit= $GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html";		
	    }else
		{
		$view_file_edit=$GLOBALS['SCup']->SCup_view_root."/content/content_edit.view.html";
	    }

	    $view_scup_list=read_file($view_file_indexlist);
	    $view_scup_add=read_file($view_file_indexadd);		
	    $view_scup_edit=read_file($view_file_indexedit);
		
	    $view_admin_list=read_file($view_file_list);
	    $view_admin_add=read_file($view_file_add);			
	    $view_admin_edit=read_file($view_file_edit);
			
        include_once(ROOT_PATH . '/lib/div.lib.php');
		$phpscupdiv= new PhpSCup_div($table_id,'');
        $phpscupdiv_array = $phpscupdiv->get_phpscupdiv($table_id);
		$phpscupdiv_temp_array = array();
		$phpscupdiv_tips_array = array();		

        foreach($phpscupdiv_array as $key =>$value)
		{
		 $phpscupdiv_temp_array[$value['icon']] = str_replace(array("&lt;","&gt;"),array("<",">"),$value['phpdiv']);
		 $phpscupdiv_tips_array[$value['icon']] = $value['tips'];		 
		} 
	
        $phpscuplistarray = $phpscupdiv->get_module_list_array($table_id);
		
        $view_scup_list = $phpscupdiv->_get_content_html($view_scup_list,$phpscuplistarray);		
        $view_scup_add = $phpscupdiv->_get_content_html($view_scup_add,$phpscupdiv_temp_array,$phpscupdiv_tips_array);
        $view_scup_edit = $phpscupdiv->_get_content_html($view_scup_edit,$phpscupdiv_temp_array,$phpscupdiv_tips_array);		
								
        $view_admin_list = $phpscupdiv->_get_content_html($view_admin_list,$phpscuplistarray);
        $view_admin_add = $phpscupdiv->_get_content_html($view_admin_add,$phpscupdiv_temp_array,$phpscupdiv_tips_array);		
        $view_admin_edit = $phpscupdiv->_get_content_html($view_admin_edit,$phpscupdiv_temp_array,$phpscupdiv_tips_array);		
		
     	write_file($this->view_scup_dir."/content_{$table_id}_list.view.html",$view_scup_list);
	    write_file($this->view_scup_dir."/content_{$table_id}_add.view.html",$view_scup_add);
	    write_file($this->view_scup_dir."/content_{$table_id}_edit.view.html",$view_scup_edit);		
			
     	write_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html",$view_admin_list);
	    write_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html",$view_admin_add);
	    write_file($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html",$view_admin_edit);

   	    if(!is_writable($this->view_scup_dir."/content_{$table_id}_list.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$table_id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($this->view_scup_dir."/content_{$table_id}_add.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$table_id}_add.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($this->view_scup_dir."/content_{$table_id}_edit.view.html"))
	    {	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$table_id}_edit.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();	
	    }

				
   	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_list.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_add.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }
	    if(!is_writable($GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html"))
	    {	
		 $notice = &get_message(array('msg'=>$GLOBALS['SCup']->SCup_view_root."/content_{$table_id}_edit.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();	
	    }
		 if($yes=='no')
		 {
		 $notice = &get_message(array('msg'=>"模块修改成功!",'url'=>'?app=cache','title'=>'Notice'));
		 $notice ->display();
		 }
    }
	
    function get_field_str($name,$type,$length = '',$isnull = false,$default = '',$extra = '', $comment = '',$default_orig = false)
    {

        $is_timestamp = strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1;

        $query = $this->str_backquote($name) . ' ' . $type;

        if ($length != '' && !preg_match('@^(data|datetime|time|tinyblob|tinytext|blob|text|mediumblob|mediumtext|longblob|longtext)$@i', $type)) 
		{
            $query .= '(' . $length . ')';
        }
        if ($isnull !== false) 
		{
            if (!empty($isnull)) 
			{
                $query .= ' NOT NULL';
            } else 
			{
                $query .= ' NULL';
            }
        }
		if ($extra !== 'AUTO_INCREMENT' && (strlen($default) || $default != $default_orig)) 
		{
            if (strtoupper($default) == 'NULL') 
			{
                $query .= ' DEFAULT NULL';
            } else 
			{
                if (strlen($default)) 
				{
                    if ($is_timestamp) 
					{
                        $query .= ' DEFAULT ' . $this->str_sqlAddslashes($default);
                    } else 
					{
                        $query .= ' DEFAULT \'' . $this->str_sqlAddslashes($default) . '\'';
                    }
                }
            }
        }

        if (!empty($extra)) 
		{
            $query .= ' ' . $extra;

        }
		
        if (get_db()->version() >= '4.1' && !empty($comment)) 
		{
            $query .= " COMMENT '" . $this->str_sqlAddslashes($comment) . "'";
        }
        return $query;
    } 

    function str_backquote($name)
    {
        if (strlen($name) && $name !== '*') 
		{
            return '`' . str_replace('`', '``', $name) . '`';
        } else 
		{
            return $name;
        }
    } 

    function str_sqlAddslashes($string = '')
    {
        $string = str_replace('\\', '\\\\', $string);
        $string = str_replace('\'', '\'\'', $string);
        return $string;
    }
		

 function get_view_data()
    {
	   if ($this->view_data == null)
       {
	        $dirname = $this->view_scup_dir.'/content';		
		    $this->view_data = get_all_dirname($dirname);
	   }
	   
	   return $this->view_data;
	  	
    }
		
    function cagryadd()
    {

        $id = intval($_GET['id']);

		$TB_module = &$this->_model('module');	 
		
		$data = $TB_module->oneshow($id);
        $this->type = $data['appname'];
		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$catgystr = $category->html_format_category($catgydata,0);	

        $this->assign('catgystr', $catgystr);	
		
        $this->assign('appname', $this->type);
        $this->assign('appid', $id);

        $this->assign('viewdata', $this->get_view_data());
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('module_cagryadd.view.php');
    }
	
    function editcatgy()
    {
	
		
		$id= intval($_GET['id']);
		$appid= intval($_GET['appid']);
		$TB_module = &$this->_model('module');			
		$tempdata = $TB_module->oneshow($appid);
        $this->type = $tempdata['appname'];
		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$data = $category->oneshow($id);
		
	    $catgystr = $category->html_format_category($catgydata,$data['parent_id'],0,0,$id);	

	    if(is_file($this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html"))
		{
		$view_file_show = $this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html";		
	    }else
		{
		$view_file_show = $this->view_scup_dir."/content/".$data['viewshowname'];
	    }
	    $view_scup_show=str_replace(array("<",">",'"',"'"),array("&lt;","&gt;",'&quot;','&#39;'),read_file($view_file_show));
		
        $this->assign('view_file_show', $view_file_show);		
        $this->assign('view_scup_show', $view_scup_show);	

	    if(is_file($this->view_scup_dir."/content_{$appid}_{$id}.view.html"))
		{
		$view_file_index = $this->view_scup_dir."/content_{$appid}_{$id}.view.html";		
	    }else
		{
		$view_file_index = $this->view_scup_dir."/content/".$data['viewname'];
	    }		
	    $view_scup_index=str_replace(array("<",">",'"',"'"),array("&lt;","&gt;",'&quot;','&#39;'),read_file($view_file_index));
        $this->assign('view_file_index', $view_file_index);		
        $this->assign('view_scup_index', $view_scup_index);	

        $this->assign('data', $data);
        $this->assign('catgystr', $catgystr);
        $this->assign('viewdata', $this->get_view_data());		
        $this->assign('appname', $this->type);
        $this->assign('appid', $appid);			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('module_cagryedit.view.php');
    }
	
    function cagrylist($cid=0)
    {
        if(!isset($_GET['id']))
		{
		$_GET['id'] ='';
		} 
        $id = intval($_GET['id']);
        if($cid)$id = $cid;

		$TB_module = &$this->_model('module');	 
		
		$data = $TB_module->oneshow($id);
        $this->type = $data['appname'];

	    $category = & $GLOBALS['SCup']->_get_category();

						
		$catgydata = $category->show($this->type);
		$catgydata = $category->get_list_category($catgydata);		
					
        $this->assign('catgydata', $catgydata);	

        $this->assign('appname', $this->type);

        $this->assign('appid', $id);
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('module_cagrylist.view.php');
    }

    function cyaddpost()
    {

	     $data = $_POST['data'];
		include(ROOT_PATH."/lib/pinyin.lib.php"); 
		$p = new pingyin();
        if (isset($data['pinyin'])&&!empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['pinyin'],1);
        }
		if (empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['cat_name'],1);
        } 		 
		 
         $appid = intval($_POST['id']);
		$TB_module = &$this->_model('module');			
		$tempdata = $TB_module->oneshow($appid);
        $this->type = $tempdata['appname'];
		 if(empty($data['viewname']))
		 {
		 $data['viewname'] = 'content.view.html';
		 }

		 if(empty($data['viewshowname']))
		 {
		 $data['viewshowname'] = 'contentshow.view.html';
		 }

		 $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		 $id = $category->post($data);
		 write_router_cache(array($data['pinyin']=>array('app' => $this->type,'act' => 'index','catid' => $id)));
		 $category->write_cache($this->type);
		 $this->write_module_default_scupshow_html($appid,$id,$data['viewshowname']);			 
		 $this->write_module_default_scupcy_html($appid,$id,$data['viewname']);		 	 		 
		 $this->cagrylist($appid);

    }


    function cyeditpost()
    {
	     $appid = $_POST['appid'];

	     $id = $_POST['id'];
	     $data = $_POST['data'];
		include(ROOT_PATH."/lib/pinyin.lib.php"); 
		$p = new pingyin();
        if (isset($data['pinyin'])&&!empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['pinyin'],1);
        }
		if (empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['cat_name'],1);
        } 		 
		 
         $scupindexdata = $_POST['scupindex'];	
         $scupshowdata = $_POST['scupshow'];	
		 if(empty($data['viewname']))
		 {
		 $data['viewname'] = 'content.view.html';
		 }
		 
		 if(empty($data['viewshowname']))
		 {
		 $data['viewshowname'] = 'contentshow.view.html';
		 }

		 
		$TB_module = &$this->_model('module');			
		$tempdata = $TB_module->oneshow($appid);
        $this->type = $tempdata['appname'];

	     $category = & $GLOBALS['SCup']->_get_category();
	
		 $temp_data = $category->oneshow($id);
         if($temp_data['viewname'] != $data['viewname'])
		 {
		 $this->write_module_default_scupcy_html($appid,$id,$data['viewname']);		 
		 }
		 else
		{
		    if(!empty($scupindexdata))
			{
	             $view_scup_index = stripslashes($scupindexdata);
	             $view_scup_index=str_replace(array("&lt;","&gt;",'&quot;','&#39;'),array("<",">",'"',"'"),$view_scup_index);				 		
     	         write_file( $this->view_scup_dir."/content_{$appid}_{$id}.view.html",$view_scup_index);				
   	            if(!is_writable($this->view_scup_dir."/content_{$appid}_{$id}.view.html"))
		        {	
		        $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$appid}_{$id}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			
			}
		 
		 }

         if($temp_data['viewshowname'] != $data['viewshowname'])
		 {
		 $this->write_module_default_scupshow_html($appid,$id,$data['viewshowname']);		 
		 }
		 else
		{
		    if(!empty($scupshowdata))
			{
	             $scupshowdata = stripslashes($scupshowdata);
	             $scupshowdata=str_replace(array("&lt;","&gt;",'&quot;','&#39;'),array("<",">",'"',"'"),$scupshowdata);				 		
     	         write_file( $this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html",$scupshowdata);				
   	            if(!is_writable($this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html"))
		        {	
		        $notice = &get_message(array('msg'=>$this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			
			}
		 
		 }
						
		 $category->editaction($id,$data);
		 write_router_cache(array($data['pinyin']=>array('app' => $this->type,'act' => 'index','catid' => $id)),'edit');
		 $category->write_cache($this->type);	
		 	 		 
		 $this->cagrylist($appid);

    }

	 function delcatgy()
    {
		$id= intval($_GET['id']);		
		$appid= intval($_GET['appid']);
		$TB_module = &$this->_model('module');			
		$data = $TB_module->oneshow($appid);
        $this->type = $data['appname'];

		 $db = & get_db();
	     $rs=$db->get_one("SELECT count(*) AS num FROM ".DB_PREFIX."content_{$appid} WHERE cat_id='$id' ");	
	     if($rs['num'])
		 {	
		 $notice = &get_message(array('msg'=>'本分类还有内容了,请先删除内容','url'=>'','title'=>'Notice'));
		 $notice ->display();			
	     }

	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->del($id);
		 write_router_cache($id,'del');			
		$category->write_cache($this->type);

         $dir_array = array($this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html",
		 $this->view_scup_dir."/content_{$appid}_{$id}.view.html",
		 );
		 foreach ($dir_array as $key => $value)
		 {
		    if(!is_dir($value)&&file_exists($value))
		    {
		     del_file($value);	
		    }		 
		 }		
					      
		$this->cagrylist($appid);   
    }

    function viewmanage()
    {	
        if(!isset($_GET['post']))
		{
		$_GET['post'] = '';
		}
		if($_GET['post']=='do')
		{
		
		    $isstop = $_POST['isstop'];			


			$GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop']=$isstop;
		   $notice = &get_message(array('msg'=>"提交成功",'url'=>'?app=module&act=viewmanage','title'=>'Notice'));
		   $notice ->display();				
		}
		
		
		if(!isset($GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop']))
		{
		$GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop']=0;
		}	
        $this->assign('isstop', $GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop']);
					
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('module_viewmanage.view.php');
    }
	
	function write_module_default_scupcy_html($tableid =0,$catid=0,$viewname='content.view.html')
    {	
	
	    $view_scup_index = stripslashes(read_file($this->view_scup_dir.'/content/'.$viewname));
	
     	write_file($this->view_scup_dir."/content_{$tableid}_{$catid}.view.html",$view_scup_index);

   	    if(!is_writable($this->view_scup_dir."/content_{$tableid}_{$catid}.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$tableid}_{$catid}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }


    }

	function write_module_default_scupshow_html($tableid =0,$catid=0,$viewshowname='contentshow.view.html')
    {	
	    $view_scup_show = stripslashes(read_file($this->view_scup_dir.'/content/'.$viewshowname));		
     	write_file($this->view_scup_dir."/contentshow_{$tableid}_{$catid}.view.html",$view_scup_show);		

   	    if(!is_writable($this->view_scup_dir."/contentshow_{$tableid}_{$catid}.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/contentshow_{$tableid}_{$catid}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }

    }
    function get_sx_cache($id)
    {

        $data = include(ROOT_PATH.'/data/sx/sx_'.$id.'.php');  
		return $data['name'];
    }

}

?>